﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JobDemo01.Job
{
    internal static class ClientExtensions
    {
        public static async Task Apply(this ISEMClient client, ScanSettings scanSettings)
        {
            var sw = Stopwatch.StartNew();
            var settings = client.Settings;
            settings.SetAbc(scanSettings.IsAbcEnabled, scanSettings.AbcMethod, scanSettings.AbcLevel);
            await settings.SetImageSize((ushort)scanSettings.ScanWidth).ConfigureAwait(false);
            await settings.SetMainAmplifier(scanSettings.Contrast, scanSettings.Brightness).ConfigureAwait(false);
            await settings.SetDotAverage((ushort)scanSettings.DotAvg).ConfigureAwait(false);
            await settings.SetLineAverage((ushort)scanSettings.LineAvg).ConfigureAwait(false);
            await settings.SetFrameAverage((ushort)scanSettings.FrameAvg).ConfigureAwait(false);
            await settings.SetFov(scanSettings.FOV).ConfigureAwait(false);
            await settings.SetAngle(client.Condition.Angle, scanSettings.Rotation).ConfigureAwait(false);
            Log.Information($"ApplyScanSettings took {sw.Elapsed}");
        }

        public static async Task ApplyAvg(this ISEMClient client, int dot, int line, int frame)
        {
            var settings = client.Settings;
            await settings.SetDotAverage((ushort)dot).ConfigureAwait(false);
            await settings.SetLineAverage((ushort)line).ConfigureAwait(false);
            await settings.SetFrameAverage((ushort)frame).ConfigureAwait(false);
        }
    }
}
